package vn.personal.anhht.bloback12.adapter;

import java.util.ArrayList;

import vn.personal.anhht.bloback12.activity.R;
import vn.personal.anhht.bloback12.bean.LogObject;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class LogItemAdapter extends ArrayAdapter<LogObject>{
	
	private ArrayList<LogObject> items;
	public LogItemAdapter(Context context, int textViewResourceId,
	        ArrayList<LogObject> items) {
		super(context, textViewResourceId, items);
		this.items = items;
		
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View v = convertView;
        if (v == null) {
            LayoutInflater vi = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = vi.inflate(R.layout.custom_row_log, null);
        }
        final LogObject item = items.get(position);
        if(item != null){
        	
        	TextView tvName = (TextView)v.findViewById(R.id.tv_plog_name);
        	if(tvName != null){ 
        		if(item.getName() == null){
        			tvName.setText("No name");
        		}else{
        			tvName.setText(item.getName());
        		}
        	}
        	TextView tvPhone = (TextView)v.findViewById(R.id.tv_plog_phone);
        	if(tvPhone != null) tvPhone.setText(item.getPhone());
        	TextView tvTime = (TextView)v.findViewById(R.id.tv_plog_time);
        	if(tvTime != null) tvTime.setText(item.getTime());
        	int type;
        	type = item.getType();
        	/*
			 * miss = 0x3 out = 0x2 in= 0x1
			 */
        	if(type == 1){
        		ImageView iv = (ImageView)v.findViewById(R.id.iv_plog);
        		//iv.setImageResource(R.drawable.ic_incall);
        		iv.setImageResource(android.R.drawable.sym_call_incoming);
        	}
        	else if(type == 0x2)
        	{
        		ImageView iv = (ImageView)v.findViewById(R.id.iv_plog);
        		iv.setImageResource(android.R.drawable.sym_call_outgoing);
        		//iv.setImageResource(R.drawable.ic_outcall);
        	}
        	else if(type == 0x3){
        		ImageView iv = (ImageView)v.findViewById(R.id.iv_plog);
        		iv.setImageResource(android.R.drawable.sym_call_missed);
        	}
        	//iv.setImageDrawable(getResources().getDrawable(R.drawable.ic_arrow));
        	
        	/*CheckBox cbSelect = (CheckBox)v.findViewById(R.id.cb_select);
        	
        	cbSelect.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					CheckBox cbox = (CheckBox)v.findViewById(R.id.cb_select);
					if(cbox.isChecked()){
						selectedItems.add(item);
						Toast.makeText(v.getContext(), selectedItems.size() + "__sdfaf" + item.getName(), Toast.LENGTH_SHORT).show();
					}else{
						selectedItems.remove(item);
						Toast.makeText(v.getContext(), selectedItems.size() + "__sdfaf" + item.getPhone(), Toast.LENGTH_SHORT).show();
					}
				}
        		
        	});*/
        }
		
		
		return v;
		
	}
}
